﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using PlaneWar.Helper;

namespace PlaneWar
{
    /// <summary>
    /// MainWindow.xaml 的交互逻辑
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();

        }
        public static Button btn_strat;
        static bool IsFirst = true;
        private void button2_Click(object sender, RoutedEventArgs e)
        {
            if (IsFirst)
            {
                //主界面增加自己飞机
                Engine_Helper.Add_MyPlane();

                //开启线程
                Engine_Helper.Plane_Engine();

                button2.IsEnabled = false;
                IsFirst = false;
            }
            else
            {
                Engine_Helper.IsOver = false;
                (Engine_Helper.myPlane.DataContext as Myplane_Helper).Init();
            }


        }

        private void Window_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.Key == Key.Down)
                Engine_Helper.Direction_Y = direction_Y.Down;
            if (e.Key == Key.Up)
                Engine_Helper.Direction_Y = direction_Y.Up;
            if (e.Key == Key.Left)
                Engine_Helper.Direction_X = direction_X.Left;
            if (e.Key == Key.Right)
                Engine_Helper.Direction_X = direction_X.Right;
        }

        private void Window_KeyUp(object sender, KeyEventArgs e)
        {
            if (e.Key == Key.Down)
                Engine_Helper.Direction_Y = direction_Y.Stop;
            if (e.Key == Key.Up)
                Engine_Helper.Direction_Y = direction_Y.Stop;
            if (e.Key == Key.Left)
                Engine_Helper.Direction_X = direction_X.Stop;
            if (e.Key == Key.Right)
                Engine_Helper.Direction_X = direction_X.Stop;
        }

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            Engine_Helper.win_helper = new WinMain_helper();
            Engine_Helper.win_helper.Fraction = 0;
            Engine_Helper.WinMain = this;
            Engine_Helper.Win_canvas = User_canvas;
            SPInfo.DataContext = Engine_Helper.win_helper;
            btn_strat = button2;
            Engine_Helper.AddBack();
        }
    }
}
